<template>
    <div class="m-main">
        <div class="m-container">
            <div class="m-login">
                <h2 class="m-title">会员登录</h2>
                <div class="m-under-line">
                </div>
                <van-form @submit="onSubmit">
                    <van-field
                            style="margin-bottom: 20px"
                            v-model="userName"
                            name="userName"
                            label="用户名"
                            placeholder="用户名"
                            :rules="[{ required: true, message: '请填写用户名' }]"
                    />
                    <van-field
                            v-model="password"
                            type="password"
                            name="password"
                            label="密码"
                            placeholder="密码"

                            :rules="[{ required: true, message: '请填写密码' }]"
                    />
                    <div style="margin: 16px;">
                        <van-button round block type="info" native-type="submit">立即登录</van-button>
                    </div>
                </van-form>
                <div class="m-text-right">
                    <p>您还不是我们的会员？
                        <router-link to="/register" class="m-a">立即注册</router-link>
                    </p>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
    import {toLogin} from "../../utils/apis";
    import storage from "../../utils/sessionUtils";
    export default {
        name: "Login",
        data() {
            return {
                userName: 'test1',
                password: '12345678'
            }
        },
        methods: {
            onSubmit(values) {
                toLogin({...values}).then(res => {
                    console.log(res)
                    storage.set("userInfo",res.data)
                    this.$router.push("/")
                })
            },
        }
    }
</script>

<style scoped>
    .m-main {
        background: url("./images/bg.jpg") no-repeat;
    }

    .m-container {
        height: 707px;
        width: calc(100% - 24px);
        padding: 30% 12px 0 12px;
        z-index: 99;
    }

    .m-login {
        margin: 0 auto;
    }

    .m-a {
        color: #25b4ed;
    }

    .m-title {
        text-align: center;
        color: #25b4ed;
        margin-bottom: 50px;
    }

    .m-under-line {
        height: 2px;
        background: #1baeae;
        margin: 30px 0;
    }

    .m-text-right {
        margin: 10px 0;
        text-align: right;
        color: white;
    }
</style>
